window.onload = function(){

}

$(function() {
    /*
TODO 点击事件如何与数据进行连接？
 */
    window._AMapSecurityConfig = {
        securityJsCode:'05845738c5e8972ae0c3ccfdc1570033',
    }
    let container = document.getElementById("container");
    //如何讲获取的weidu值存储成一个double数组
    let map = new AMap.Map(container);
    let bookName = $('.bookName').text();
    let authorName = $('.authorName').text();
    let time = $('.time').text();
    let location = $('.location').text();
    let jingduType = $('.jingdu');
    let jingdu = [];
    for (var i = 0; i < jingduType.length; i++) {
        jingdu[i] = jingduType[i].innerHTML;
    }
    let weiduType = $('.weidu');
    let weidu = [];
    for (let i = 0; i <weiduType.length; i++) {
        weidu[i] = weiduType[i].innerHTML;
    }

    let lineArr = [];

    for (let j = 0; j < jingdu.length; j++) {
        let arr = [];
        arr.push(jingdu[j]);
        arr.push(weidu[j]);
        lineArr.push(arr);
    }

    let polyline = new AMap.Polyline({
        path: lineArr,          //设置线覆盖物路径
        strokeColor: "#3366FF", //线颜色
        strokeWeight: 5,        //线宽
        strokeStyle: "solid",   //线样式
    });
    map.add(polyline);

    var infoWindow = new AMap.InfoWindow({ //创建信息窗体
        isCustom: true,  //使用自定义窗体
        content:'<div>信息窗体</div>', //信息窗体的内容可以是任意html片段
        offset: new AMap.Pixel(16, -45)
    });
    var onMarkerClick  =  function(e) {
        console.log(e.lnglat);
        infoWindow.open(map, e.target.getPosition());//打开信息窗体
        //e.target就是被点击的Marker
    }

    for (let i = 0; i < jingdu.length; i++) {
        let marker = new AMap.Marker({
            position:lineArr[i]//位置
        })
        map.add(marker);
        marker.on('click',onMarkerClick);//绑定click事件
    }

})